package com.example.controller;

import cn.hutool.core.lang.Dict;
import com.example.common.Result;
import com.example.entity.ActivitySign;
import com.example.entity.Order;
import com.example.mapper.OrderMapper;
import com.example.service.ActivitySignService;
import com.example.service.orderService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 活动报名前端操作接口
 **/
@RestController
@RequestMapping("/order")
public class orderController {

    private static final Logger log = LoggerFactory.getLogger(orderController.class);
    @Resource
    private ActivitySignService activitySignService;


    @Resource
    private orderService orderServe;

    @Resource
    private OrderMapper orderMapper;

    @GetMapping("/jwt")
    public Result jwt() {
        return Result.success();
    }

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody Order activitySign) {
        orderServe.add(activitySign);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        orderServe.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        orderServe.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody Order activitySign) {
        orderServe.updateById(activitySign);

        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Order activitySign = orderServe.selectById(id);
        return Result.success(activitySign);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(Order activitySign) {
        List<Order> list = orderServe.selectAll(activitySign);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(Order activitySign,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Order> page = orderServe.selectPage(activitySign, pageNum, pageSize);
        return Result.success(page);
    }

    @GetMapping("/selectCount")
    public Result selectCount() {
        List<Dict> list = activitySignService.selectCount();
        return Result.success(list);
    }


    @GetMapping("/getlist")
    public Result getlist(Order activitySign) {
        List<Order> list = orderMapper.selectAllLeftUser(activitySign);
        return Result.success(list);
    }

}